<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<ul class="breadcrumb panel">
    <li><a href="javascript:backMainFun();"><i class="fa fa-home"></i> 首页</a></li>
    <li class="active">待签收任务</li>
</ul>

<div class="panel">
    <div class="panel-body">
        <form action="" onsubmit="return false;">
            <div class="row">
                <div class="col-xs-3">
                    <div class="form-group marBN">
                        <div class="iconic-input">
                            <i class="fa fa-btc"></i>
                            <input type="text" class="form-control" id="query_TITLE" name="query_TITLE" placeholder="按标题查找">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group marBN">
                        <div class="iconic-input">
                            <i class="fa fa-male"></i>
                            <input type="text" class="form-control" id="query_CREATE_USER_" name="query_CREATE_USER_" placeholder="按申请人查找">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <button id="searchBtn" type="submit" class="btn btn-success"><i class="glyphicon glyphicon-search"></i> 查找</button>
                    <button type="reset" class="btn btn-warning"><i class="fa fa-trash-o"></i> 清空</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="panel">
    <header class="panel-heading">
        待签收列表
    </header>
    <div class="panel-body">
        <table id="table1"
               data-toggle="table"
               data-classes="table table-hover"
               data-sort-order="asc"
               data-method="get"
               data-data-type="json"
               data-pagination="true"
               data-show-columns="true"
               data-minimum-count-columns="3"
               data-page-size="10"
               data-locale="zh-CN"
               data-striped="true"
        ></table>
    </div>
</div>

<script>

    $('#searchBtn').click(function(){
        $("#table1").bootstrapTable('refreshOptions',
                {
                    pagination: true,
                    dataShowToggle: true,
                    url: "${ctx}/taskUnassign/getTaskUnassignList",
                    queryParams: function (params) {
                        return $.extend({}, params, {
                            query_CREATE_USER_: $('#query_CREATE_USER_').val(),
                            query_TITLE:$('#query_TITLE').val()
                        });
                    }
                });
    });


    $("#table1").bootstrapTable({
        contentType: "application/x-www-form-urlencoded",
        method: 'post',
        sidePagination: 'server',
        toolbar: '#toolbar',
        pagination: true,
        dataShowToggle: true,
        url:"${ctx}/taskUnassign/getTaskUnassignList",
        columns: [
            {
                field: 'num',
                title: '序号',
                formatter:function (value, row, index) {
                    if($('.pagination').find('li.active').find('a').text()){
                        var numbers = parseInt([parseInt($('.pagination').find('li.active').find('a').text())-1]* parseInt($('.page-size').text()) )+ parseInt(index+1);
                        return [
                            numbers
                        ].join('') ;
                    }else{
                        return [
                            index+1
                        ].join('') ;
                    }

                }
            }, {
                field: 'tITLE',
                title: "标题"
            }, {
                field: 'nAME_',
                title: "当前环节"
            }, {
                field: 'pARENT_USER',
                title: "发送人"
            }, {
                field: 'cREATE_TIME_',
                title: "发送时间",
                formatter: formatterDate
            }, {
                field: 'cREATE_USER_',
                title: "申请人"
            }, {
                field: 'sTART_TIME_',
                title: "发起时间",
                formatter: formatterDate
            },{
                field: 'iD_',
                title: '操作',
                formatter:option
            }]
    });
    function option(value,row){
        return [
            '<button class="btn btn-xs btn-info" onclick="assignFun(\'' + value + '\')"><i class="glyphicon glyphicon-edit"></i> 签收</button>&nbsp;&nbsp;',
            '<button class="btn btn-xs btn-success" onclick="detailView(\'' + value + '\')"><i class="fa fa-eye"></i> 查看</button>&nbsp;&nbsp;',
        ].join('');
    }
    function formatterDate(value) {
        return value.substring(0,19);
    }
    function userNumFun(value, row){
        if(value==0){
            return [
                '<a class="text-info" href="javascript:userListFun(\'' + row.iD_ + '\');">添加用户</a>'
            ].join('');
        }else{
            return [
                '<a class="text-info" href="javascript:userListFun(\'' + row.iD_ + '\');">'+value+'个 <i class="fa fa-search-plus"></i></a>'
            ].join('');
        }
    }
    function detailView(value) {
        loadFun("/taskWait/toHandle?id="+value+"&showForm=0&assign=1");
    }
    function assignFun(value) {
        zConfirm('确认签收？');
        confirmOk.click(function(){
            $.ajax({
                url: "${ctx}/taskUnassign/taskAssign",
                type: 'post',
                data: {
                    id: value
                },
                success: function (data) {
                    zConfirmHide();
                    if (data.success) {
                        $("#table1").bootstrapTable('refresh',{url:"${ctx}/taskUnassign/getTaskUnassignList"});
                        setTimeout(function(){
                            zAlert(data.msg)
                        },100);
                    } else {
                        zAlert(data.msg);
                    }
                }
            })
        });
    }
</script>